/*
#####################################################################
####################	   T R I B U I T 		#####################
#####################################################################

Copyright (C) 2010  Christoph Schnack, Berlin (Germany)

This file is part of Tribuit.

    Tribuit is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Tribuit is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Tribuit.  If not, see <http://www.gnu.org/licenses/>.


########################################################################
*/
package OtherDialogs;

import java.awt.*;
import java.awt.event.*;
import java.util.Locale;

import javax.swing.*;

import GuiTools.CustomTextArea;
import GuiTools.Header;
import Mainframe.Mainframe;
import Settings.Language;
import Settings.Settings;
import Storage.Storage;

public class Introduction{
	JDialog inFrame;
	Language LANG;
	Settings SET;
	CustomTextArea area;
	JCheckBox cb;
	Header header;
	JButton okBtn;
	Mainframe MAINFRAME;
	Storage MAINVOC;
	JScrollPane jsp;
	public Introduction(Mainframe mf,Storage mv,Settings s){
		SET = s;
		MAINFRAME=mf;
		MAINVOC=mv;
		LANG = SET.getLanguage();
		header = new Header(LANG.getWelcome());
		inFrame = new JDialog(MAINFRAME,LANG.getWelcome(),true);
		area = new CustomTextArea("");
		area.setText(LANG.getIntroduction()+"\n\n"+LANG.getIntroduction2()+"\n\n"+LANG.getIntroduction3());
		area.setFont(new Font(Font.SANS_SERIF,Font.BOLD,15));
		cb = new JCheckBox(LANG.getDontShowAnyLonger(),false);
		JRadioButton rbA = new JRadioButton("english");
		rbA.setOpaque(false);
		rbA.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				SET.setLanguage("english");
				LANG = SET.getLanguage();
				area.setText(LANG.getIntroduction()+"\n\n"+LANG.getIntroduction2()+"\n\n"+LANG.getIntroduction3());
				cb.setText(LANG.getDontShowAnyLonger());
				header.setText(LANG.getWelcome());
				inFrame.setTitle(LANG.getWelcome());
				okBtn.setText(LANG.getAccept());
				inFrame.pack();
				SwingUtilities.invokeLater(new Runnable(){
					public void run(){
						jsp.getVerticalScrollBar().setValue(0);
					}
				});
			}
		});
		JRadioButton rbB = new JRadioButton("german");
		rbB.setOpaque(false);
		rbB.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				SET.setLanguage("german");
				LANG = SET.getLanguage();
				area.setText(LANG.getIntroduction()+"\n\n"+LANG.getIntroduction2()+"\n\n"+LANG.getIntroduction3());
				cb.setText(LANG.getDontShowAnyLonger());
				header.setText(LANG.getWelcome());
				inFrame.setTitle(LANG.getWelcome());
				okBtn.setText(LANG.getAccept());
				inFrame.pack();
				SwingUtilities.invokeLater(new Runnable(){
					public void run(){
						jsp.getVerticalScrollBar().setValue(0);
					}
				});
			}
		});
		if(SET.getCurrentLanguage().equals("english"))rbA.setSelected(true);
		else rbB.setSelected(true);
		ButtonGroup bg = new ButtonGroup();
		bg.add(rbA);
		bg.add(rbB);
		okBtn = new JButton(LANG.getAccept());
		okBtn.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				inFrame.dispose();
				String start="true";
				if(cb.isSelected())start="false";
				SET.setFirstStart(start);
				SET.save();
				SwingUtilities.invokeLater(new Runnable(){
					public void run(){
						MAINFRAME.updateMainframe();
					}
				});
			}
		});
		JPanel buttonPanel = new JPanel();
		buttonPanel.add(cb);
		buttonPanel.add(rbA);
		buttonPanel.add(rbB);
		JPanel okPanel = new JPanel();
		okPanel.add(okBtn);
		JPanel southPanel = new JPanel();
		southPanel.setLayout(new BoxLayout(southPanel,BoxLayout.Y_AXIS));
		southPanel.add(buttonPanel);
		southPanel.add(okPanel);
		JPanel centerPanel = new JPanel();
		centerPanel.setLayout(new GridBagLayout());
		GridBagConstraints gbc = new GridBagConstraints();
		gbc.insets = new Insets(20,20,20,20);
		jsp = new JScrollPane(area);
		jsp.setPreferredSize(new Dimension(300,150));
		jsp.setBorder(null);
		centerPanel.add(jsp,gbc);
		inFrame.getContentPane().add(BorderLayout.NORTH,header);
		inFrame.getContentPane().add(BorderLayout.CENTER,centerPanel);
		inFrame.getContentPane().add(BorderLayout.SOUTH,southPanel);
		inFrame.setLocation(300,150);
		inFrame.pack();
		Locale l = MAINFRAME.getLocale();
		if(l.getLanguage().equals("de")) rbB.doClick();
		inFrame.setVisible(true);
		inFrame.addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent e){
				String start="true";
				if(cb.isSelected())start="false";
				SET.setFirstStart(start);
				SET.save();
				MAINFRAME.updateMainframe();
			}
		});
	}
}